/**
 * Created by HUANGFR2 on 8/24/2016.
 */
angular.module('clientApp').controller('indexController', function ($scope, $http, $location, $rootScope, constantService) {
    //console.log($location.url);
    //$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
    //
    //    //if(toState.name=="tabs.post"&&fromState.name=="tabs.orderList"){
    //    //
    //    //    //$location.path();//获取路由地址
    //    //
    //    //    $location.path('/tabs/home');//设置路由地址
    //    //
    //    //}
    //    console.log($location.url);
    //})


    $rootScope.constant = constantService;
    $scope.$on('reDishes', function (event, dishes) {
        $scope.dishes = dishes;
    })

    var req = {
        method: "GET",
        url: "clients/getSession"
    }
    $http(req)
        .then(function (res) {
            if (res.data.msg == "SUCCESS") {
                $rootScope.user = res.data.client;
            } else {
                window.location.href = '#/merchant';
            }
        })
    $scope.logout = function () {

        //window.location.href="http://localhost:3038/index.html";
        var req = {
            method: "GET",
            url: "/clients/logout",
        };
        $http(req)
            .then(function (res) {
                if (res.data.msg == "SUCCESS") {
                    $rootScope.user = null;
                } else {
                    window.location.href = '#/merchant';
                }
            })
    }
});